package gagak.framework.web.view;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/*
 * @program: ce
 * @description: jackson解析器
 * @author: houhong
 * @create: 2022-12-01 18:56
 */
public class JacksonViewResovler extends AbstractJsonView {

    private ObjectMapper objectMapper = new ObjectMapper();



    @Override
    public String getContentType() {
        return null;
    }


    @Override
    public void render(Object resultValue, HttpServletRequest request, HttpServletResponse response) throws Exception {

        String resultStr = objectMapper.writeValueAsString(resultValue);
        PrintWriter writer = response.getWriter();
        writer.print(resultStr);
        writer.flush();
        writer.close();
    }
}